<?php
/**
 * 云门店
 */
function checkRight()
{
	global $_W;return true;
	$settings = pdo_fetchcolumn('SELECT settings FROM ' . tablename('uni_account_modules') . ' WHERE module =:module AND uniacid=:uniacid', array(':module' => 'j_hmoney', ':uniacid' => $_W['uniacid']));
	$cfg = iunserializer($settings);
	$keycode = $cfg['keycode'];
	if (!$keycode) {
		$keycode = pdo_fetchcolumn('SELECT keycode FROM ' . tablename('j_hmoney_systemsetting') . ' order by id asc limit 1');
	}
	if (!$keycode) {
		exit('授权出错,0x001,没有授权码码');
	}
	$newDes = new JETSUMDES();
	$newDes->DES('jet*#Sum');
	$softStrAry = $newDes->decrypt($keycode);
	if (strpos($softStrAry, '|#|') === false) {
		exit('授权出错,0x002,授权码错误');
	}
	$softkeyAry = explode('|#|', $softStrAry);
	$siteroot = str_replace('jet-', '', $softkeyAry[0]);
	if (strpos($siteroot, '|') > 0 - 1) {
		$keyAry = explode('|', $siteroot);
		$servieIp = serverIp();
		if (strpos($keyAry[1], '.') > 0 - 1) {
			if ($keyAry[1] != $servieIp) {
				exit('授权错误,0x004,授权IP错误' . $servieIp . '-' . $keyAry[1]);
			}
		} else {
			$siteroot = $keyAry[0];
			$siteroot = str_replace('http://', '', $siteroot);
			$siteroot = str_replace('https://', '', $siteroot);
			$Wsiteroot = str_replace('https://', '', $_W['siteroot']);
			$Wsiteroot = str_replace('http://', '', $Wsiteroot);
			if ($siteroot != $Wsiteroot) {
				exit('授权错误,0x003,授权码错误');
			}
		}
	} else {
		$siteroot = str_replace('http://', '', $siteroot);
		$siteroot = str_replace('https://', '', $siteroot);
		$Wsiteroot = str_replace('https://', '', $_W['siteroot']);
		$Wsiteroot = str_replace('http://', '', $Wsiteroot);
		if ($siteroot != $Wsiteroot) {
			exit('授权错误,0x003,授权码错误');
		}
	}
	return true;
}
function check_ouath($ctrl = '')
{
	global $_W;
	$settings = pdo_fetchcolumn('SELECT settings FROM ' . tablename('uni_account_modules') . ' WHERE module =:module AND uniacid=:uniacid', array(':module' => 'j_hmoney', ':uniacid' => $_W['uniacid']));
	$cfg = iunserializer($settings);
	$keycode = $cfg['keycode'];
	if (!$keycode) {
		$keycode = pdo_fetchcolumn('SELECT keycode FROM ' . tablename('j_hmoney_systemsetting') . ' order by id asc limit 1');
	}
	if (!$keycode) {
		return false;
	}
	$newDes = new JETSUMDES();
	$newDes->DES('jet*#Sum');
	$softStrAry = $newDes->decrypt($keycode);
	if (strpos($softStrAry, '|#|') === false) {
		return false;
	}
	$softkeyAry = explode('|#|', $softStrAry);
	$siteroot = str_replace('jet-', '', $softkeyAry[0]);
	if (strpos($siteroot, '|') > 0 - 1) {
		$keyAry = explode('|', $siteroot);
		$compearkey = '';
		if (count($keyAry) == 3) {
			$compearkey = $keyAry[2];
		} else {
			if (count($keyAry) == 2) {
				$compearkey = $keyAry[1];
			} else {
				return false;
			}
		}
		if (!$compearkey) {
			return false;
		}
		if ($compearkey == $ctrl) {
			return true;
		}
	}
	return false;
}
function serverIp()
{
	return gethostbyname($_SERVER['SERVER_NAME']);
}
function check_right($right = 0, $needshopid = 1)
{
	global $_W;
	global $_GPC;
	checkRight();
	session_start();
	$shopid = $_GPC['shopid'];
	if ($shopid) {
		return $shopid;
	}
	return 0;
}
function _sendWebMessage($insertdata = array())
{
	global $_W;
	global $_GPC;
	$data = array('weid' => $_W['uniacid'], 'groupid' => intval($insertdata['shopid']), 'userid' => intval($insertdata['userid']), 'touser' => intval($insertdata['touser']), 'mtype' => $insertdata['mtype'], 'orderid' => intval($insertdata['orderid']), 'content' => $insertdata['content'], 'message' => $insertdata['message'], 'createtime' => TIMESTAMP);
	pdo_insert('j_hmoney_msg', $data);
	return true;
}
function _orderGoodsStatus($key = '')
{
	$temp = array('0' => '未处理', '1' => '已下单', '2' => '完成', '3' => '部分退款', '4' => '全部退款');
	if ($key == '') {
		return $temp;
	}
	return $temp[$key];
}
function _tableStatus($key = '')
{
	$temp = array('0' => '未付款', '1' => '已付款', '2' => '', '3' => '部分退款', '4' => '全部退款');
	if ($key == '') {
		return $temp;
	}
	return $temp[$key];
}
function _print_api($cookid = 0, $printcontent = '', $goods = array())
{
	global $_W;
	$cookTiem = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_cookprint') . ' WHERE id=:a ', array(':a' => $cookid));
	$printseparate = pdo_fetchcolumn('SELECT printseparate FROM ' . tablename('j_hmoney_group') . ' WHERE id =:a', array(':a' => $cookTiem['groupid']));
	if (!$cookTiem || !$cookTiem['ptype']) {
		return false;
	}
	if (!$printcontent) {
		return false;
	}
	$printcontent = str_replace('{厨房}', $cookTiem['title'], $printcontent);
	if ($printseparate) {
		foreach ($goods as $row) {
			$temp = '';
			$temp .= '<B>' . $row['title'] . '  --数量:' . $row['num'] . '</B><BR>';
			if ($row['taste'] || $row['ispack']) {
				if ($row['taste']) {
					$temp .= $row['taste'];
				}
				if ($row['ispack']) {
					$temp .= '(' . $row['taste'] . ')';
				}
				$temp .= '<BR>';
			}
			$temptxt = str_replace('{商品}', $temp, $printcontent);
			return _doPrint($cookTiem, $temptxt);
			break;
		}
	} else {
		$temp = '';
		foreach ($goods as $row) {
			$temp .= '<B>' . $row['title'] . '  --数量:' . $row['num'] . '</B><BR>';
			if ($row['taste'] || $row['ispack']) {
				if ($row['taste']) {
					$temp .= $row['taste'];
				}
				if ($row['ispack']) {
					$temp .= '(' . $row['taste'] . ')';
				}
				$temp .= '<BR>';
			}
		}
		$printcontent = str_replace('{商品}', $temp, $printcontent);
		return _doPrint($cookTiem, $printcontent);
	}
}
function _doPrint($cookTiem = array(), $printcontent = '', $isnew = 0)
{
	global $_W;
	$config = json_decode($cookTiem['param'], true);
	if ($cookTiem['ptype'] == 1) {
		load()->func('communication');
		$data = array('deviceNo' => $config['deviceNo'], 'key' => $config['key'], 'printContent' => $printcontent, 'times' => 1);
		$pageparama = json_encode($data);
		$resp = ihttp_request('http://open.printcenter.cn:8080/addOrder', $pageparama, '');
		if (is_error($resp)) {
			$procResult = $resp;
		}
		$result = @json_decode($resp['content'], true);
		return $result;
	}
	if ($cookTiem['ptype'] == 2) {
		require_once '../addons/j_hmoney/plug/plug_print/HttpClient.class.php';
		define('USER', $config['USER']);
		define('UKEY', $config['UKEY']);
		define('SN', $config['SN']);
		define('IP', 'api.feieyun.cn');
		define('PORT', 80);
		define('PATH', '/Api/Open/');
		define('STIME', time());
		define('SIG', sha1(USER . UKEY . STIME));
		$content = array('user' => USER, 'stime' => STIME, 'sig' => SIG, 'apiname' => 'Open_printMsg', 'sn' => SN, 'content' => $printcontent, 'times' => 1);
		$client = new HttpClient(IP, PORT);
		if (!$client->post(PATH, $content)) {
			return 'error';
		}
		return $client->getContent();
	}
	if ($cookTiem['ptype'] == 3) {
		require_once '../addons/j_hmoney/plug/plug_print/HttpClient.class.php';
		define('MEMBER_CODE', $config['MEMBER_CODE']);
		define('FEYIN_KEY', $config['FEYIN_KEY']);
		define('DEVICE_NO', $config['DEVICE_NO']);
		define('FEYIN_HOST', 'my.feyin.net');
		define('FEYIN_PORT', 80);
		$msg = array('memberCode' => MEMBER_CODE, 'msgDetail' => $printcontent, 'deviceNo' => DEVICE_NO, 'msgNo' => time() + 1, 'reqTime' => number_format(1000 * time(), 0, '', ''));
		$content = $msg['memberCode'] . $msg['msgDetail'] . $msg['deviceNo'] . $msg['msgNo'] . $msg['reqTime'] . FEYIN_KEY;
		$msg['securityCode'] = md5($content);
		$msg['mode'] = 2;
		$client = new HttpClient(FEYIN_HOST, FEYIN_PORT);
		if (!$client->post('/api/sendMsg', $msg)) {
			return 'faild';
		}
		return $client->getContent();
	}
	if ($cookTiem['ptype'] == 4) {
		require_once '../addons/j_hmoney/plug/plug_10ss/YlyService.class.php';
		load()->func('file');
		$dir_url = '../attachment/j_hmoney/10ss/' . $_W['uniacid'] . '/' . $config['machine_code'] . '/';
		mkdirs($dir_url);
		$printApi = new ylyApi();
		$printApi->client_secret = $config['client_secret'];
		$file_path = $dir_url . 'token.txt';
		$token = '';
		if (!file_exists($file_path)) {
			$data = array('client_id' => $config['client_id'], 'grant_type' => 'client_credentials', 'scope' => 'all', 'issign' => true, 'uuid' => true, 'timestamp' => time());
			$msg1 = $printApi->ServiceInlet($data, 'Token');
			$msg = @json_decode($msg1, true);
			if ($msg['error']) {
				return $msg['error_description'] . $msg1;
			}
			$tempary = array('access_token' => $msg['body']['access_token'], 'refresh_token' => $msg['body']['refresh_token'], 'expires_in' => TIMESTAMP + $msg['body']['expires_in']);
			$token = $msg['body']['access_token'];
			$myfile = fopen($file_path, 'w');
			fwrite($myfile, iserializer($tempary));
			fclose($myfile);
		} else {
			$str = file_get_contents($file_path);
			$strAry = iunserializer($str);
			if ($strAry['expires_in'] < TIMESTAMP) {
				$data = array('client_id' => $config['client_id'], 'refresh_token' => $strAry['refresh_token'], 'grant_type' => 'refresh_token', 'scope' => 'all', 'issign' => true, 'uuid' => true, 'timestamp' => time());
				$msg = $printApi->ServiceInlet($data, 'Token');
				$result = @json_decode($msg, true);
				if ($result['error']) {
					return $msg['error_description'] . $msg;
				}
				$tempary = array('access_token' => $result['body']['access_token'], 'refresh_token' => $result['body']['refresh_token'], 'expires_in' => TIMESTAMP + $result['body']['expires_in']);
				$token = $result['body']['access_token'];
				$myfile = fopen($file_path, 'w');
				fwrite($myfile, iserializer($tempary));
				fclose($myfile);
			} else {
				$token = $strAry['access_token'];
			}
		}
		if (!$token) {
			return 'token获取失败';
		}
		$printcontent = str_replace('<B>', '@@2', $printcontent);
		$printcontent = str_replace('</B>', '', $printcontent);
		$printcontent = str_replace('<BR>', "\n", $printcontent);
		$data = array('client_id' => $config['client_id'], 'access_token' => $token, 'machine_code' => $config['machine_code'], 'content' => $printcontent ? $printcontent : '无打印内容', 'origin_id' => time() + 1, 'issign' => true, 'uuid' => true, 'timestamp' => time());
		$msg = $printApi->ServiceInlet($data, 'Print');
		$result = @json_decode($msg, true);
		if ($result['error']) {
			return $result['error_description'] . $data;
		}
		return 'success';
	}
}
function _cookprint($key = '')
{
	$temp = array('0' => '本地打印', '1' => '365打印机', '2' => '飞鹅打印机', '3' => '飞印打印机', '4' => '易联云(K4)');
	if ($key == '') {
		return $temp;
	}
	return $temp[$key];
}
function _skinflorder($key = '')
{
	global $_W;
	$temp = array('default' => '重餐饮', 'lightfood' => '轻餐饮', 'store' => '零售/便利店', 'hairsalon' => '美容美发');
	if ($key == '') {
		return $temp;
	}
	return $temp[$key];
}
function _getPaytpye($key = '', $shopid = 0)
{
	$temp = array('0' => '微信', '1' => '支付宝', '2' => '现金', '3' => '银行卡', '4' => '会员卡', '5' => '其他');
	if ($shopid) {
		$item = pdo_fetch('SELECT custom_pay1,custom_pay2,custom_pay3,custom_pay4 FROM ' . tablename('j_hmoney_group') . ' WHERE id=:a ', array(':a' => $shopid));
		$temp[5] = $item['custom_pay1'];
		$temp[6] = $item['custom_pay2'];
		$temp[7] = $item['custom_pay3'];
		$temp[8] = $item['custom_pay4'];
	}
	if ($key == '') {
		return $temp;
	}
	return $temp[$key];
}
function _getPrintTpye($key = '')
{
	$printType = array(1 => '收银小票', 2 => '下单小票', 3 => '厨房小票', 4 => '充值小票', 5 => '退款小票', 6 => '交班小票', 7 => '采购小票', 8 => '盘点小票', 9 => '今日汇总小票', 11 => '今日汇总商品小票');
	if ($key == '') {
		return $printType;
	}
	return $printType[$key];
}
function httpGet($url)
{
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_TIMEOUT, 500);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
	curl_setopt($curl, CURLOPT_URL, $url);
	$res = curl_exec($curl);
	curl_close($curl);
	return $res;
}
function _getFansInfo($_openid)
{
	global $_W;
	if (!$_openid) {
		return false;
	}
	load()->func('communication');
	$acid = pdo_fetchcolumn('SELECT acid FROM ' . tablename('account') . ' WHERE uniacid=:uniacid ', array(':uniacid' => $_W['uniacid']));
	$acc = WeAccount::create($acid);
	$tokens = $acc->fetch_token();
	$url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=' . $tokens . '&openid=' . $_openid;
	$content = ihttp_get($url);
	if (is_error($content)) {
		return false;
	}
	$token = @json_decode($content['content'], true);
	if (empty($token) || !is_array($token)) {
		$errorinfo = substr($content['meta'], strpos($content['meta'], '{'));
		$errorinfo = @json_decode($errorinfo, true);
		return false;
	}
	return $token;
}
function _sendText($openid, $txt)
{
	global $_W;
	$acid = pdo_fetchcolumn('SELECT acid FROM ' . tablename('account') . ' WHERE uniacid=:uniacid ', array(':uniacid' => $_W['uniacid']));
	$acc = WeAccount::create($acid);
	$data = $acc->sendCustomNotice(array('touser' => $openid, 'msgtype' => 'text', 'text' => array('content' => urlencode($txt))));
	return $data;
}
function _sendMBText($touser, $template_id, $postdata, $url = '', $topcolor = '#FF683F')
{
	global $_W;
	$acid = pdo_fetchcolumn('SELECT acid FROM ' . tablename('account') . ' WHERE uniacid=:uniacid ', array(':uniacid' => $_W['uniacid']));
	$acc = WeAccount::create($acid);
	$data = $acc->sendTplNotice($touser, $template_id, $postdata, $url, $topcolor);
	return $data;
}
function Bankpay_micropay($cfg, $fee, $banktradeno, $orderid, $code, $userid = 1, $shopid = 1)
{
	global $_W;
	if (intval($fee) < 100) {
		return array('success' => false, 'msg' => '最低金额不能低于1元');
	}
	$shop = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_group') . ' WHERE id=:a ', array(':a' => $shopid));
	$bankpaykey = $shop['bankpaykey'] ? $shop['bankpaykey'] : $cfg['bankpaykey'];
	$bankmch_id = $shop['bankmch_id'] ? $shop['bankmch_id'] : $cfg['bankmch_id'];
	load()->func('communication');
	$data = array('service' => 'unified.trade.micropay', 'version' => '2.0', 'sign_type' => 'MD5', 'mch_id' => $bankmch_id, 'out_trade_no' => $banktradeno, 'attach' => $orderid, 'body' => '收银台支付', 'total_fee' => intval($fee), 'mch_create_ip' => $cfg['mch_create_ip'], 'auth_code' => $code, 'op_user_id' => $userid, 'op_shop_id' => $shopid, 'nonce_str' => getNonceStr(32));
	$sign = MakeSign($data, $bankpaykey);
	$data['sign'] = $sign;
	$xml = ToXml($data);
	$resp = ihttp_request('https://pay.swiftpass.cn/pay/gateway', $xml);
	$result = FromXml($resp['content']);
	return $result;
}
function Bankpay_checkpay($cfg, $orderid)
{
	global $_W;
	$shopid = pdo_fetchcolumn('SELECT groupid FROM ' . tablename('j_hmoney_order') . ' WHERE bank_trade_no=:a ', array(':a' => $orderid));
	$shop = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_group') . ' WHERE id=:a ', array(':a' => $shopid));
	$bankpaykey = $shop['bankpaykey'] ? $shop['bankpaykey'] : $cfg['bankpaykey'];
	$bankmch_id = $shop['bankmch_id'] ? $shop['bankmch_id'] : $cfg['bankmch_id'];
	load()->func('communication');
	$data = array('service' => 'unified.trade.query', 'version' => '2.0', 'sign_type' => 'MD5', 'mch_id' => $bankmch_id, 'out_trade_no' => $orderid, 'nonce_str' => getNonceStr(32));
	$sign = MakeSign($data, $bankpaykey);
	$data['sign'] = $sign;
	$xml = ToXml($data);
	$resp = ihttp_request('https://pay.swiftpass.cn/pay/gateway', $xml);
	$result = FromXml($resp['content']);
	return $result;
}
function Bankpay_micropayreverse($cfg, $orderid)
{
	global $_W;
	load()->func('communication');
	$shopid = pdo_fetchcolumn('SELECT groupid FROM ' . tablename('j_hmoney_order') . ' WHERE bank_trade_no=:a ', array(':a' => $orderid));
	$shop = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_group') . ' WHERE id=:a ', array(':a' => $shopid));
	$bankpaykey = $shop['bankpaykey'] ? $shop['bankpaykey'] : $cfg['bankpaykey'];
	$bankmch_id = $shop['bankmch_id'] ? $shop['bankmch_id'] : $cfg['bankmch_id'];
	$data = array('service' => 'unified.trade.micropay.reverse', 'version' => '2.0', 'sign_type' => 'MD5', 'mch_id' => $bankmch_id, 'transaction_id' => $orderid, 'nonce_str' => getNonceStr(32));
	$sign = MakeSign($data, $bankpaykey);
	$data['sign'] = $sign;
	$xml = ToXml($data);
	$resp = ihttp_request('https://pay.swiftpass.cn/pay/gateway', $xml);
	$result = FromXml($resp['content']);
	return $result;
}
function Bankpay_refund($cfg, $orderid, $out_refund_no, $totalfee, $refundfee)
{
	global $_W;
	load()->func('communication');
	$shopid = pdo_fetchcolumn('SELECT groupid FROM ' . tablename('j_hmoney_order') . ' WHERE bank_trade_no=:a ', array(':a' => $orderid));
	$shop = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_group') . ' WHERE id=:a ', array(':a' => $shopid));
	$bankpaykey = $shop['bankpaykey'] ? $shop['bankpaykey'] : $cfg['bankpaykey'];
	$bankmch_id = $shop['bankmch_id'] ? $shop['bankmch_id'] : $cfg['bankmch_id'];
	$data = array('service' => 'unified.trade.refund', 'version' => '2.0', 'sign_type' => 'MD5', 'mch_id' => $bankmch_id, 'transaction_id' => $orderid, 'out_refund_no' => $out_refund_no, 'total_fee' => $totalfee, 'refund_fee' => $refundfee, 'op_user_id' => $cfg['bankmch_id'], 'nonce_str' => getNonceStr(32));
	$sign = MakeSign($data, $bankpaykey);
	$data['sign'] = $sign;
	$xml = ToXml($data);
	$resp = ihttp_request('https://pay.swiftpass.cn/pay/gateway', $xml);
	$result = FromXml($resp['content']);
	return $result;
}
function Bankpay_wxjspay($cfg, $fee, $banktradeno, $orderid, $openid)
{
	global $_W;
	if (intval($fee) < 100) {
		return array('success' => false, 'msg' => '最低金额不能低于1元');
	}
	$bankpaykey = $cfg['bankpaykey'];
	$bankmch_id = $cfg['bankmch_id'];
	load()->func('communication');
	$data = array('service' => 'pay.weixin.jspay', 'version' => '2.0', 'sign_type' => 'MD5', 'mch_id' => $bankmch_id, 'is_raw' => 1, 'out_trade_no' => $banktradeno, 'attach' => $orderid, 'body' => '客户在线充值', 'sub_openid' => $cfg['appid'], 'sub_openid' => $openid, 'total_fee' => intval($fee), 'mch_create_ip' => $cfg['mch_create_ip'], 'notify_url' => $_W['siteroot'] . '/addons/j_hmoney/callback.php', 'nonce_str' => getNonceStr(32));
	$sign = MakeSign($data, $bankpaykey);
	$data['sign'] = $sign;
	$xml = ToXml($data);
	$resp = ihttp_request('https://pay.swiftpass.cn/pay/gateway', $xml);
	$result = FromXml($resp['content']);
	return $result;
}
function Bankpay_checkwxpay($cfg, $orderid)
{
	global $_W;
	$bankpaykey = $cfg['bankpaykey'];
	$bankmch_id = $cfg['bankmch_id'];
	load()->func('communication');
	$data = array('service' => 'unified.trade.query', 'version' => '2.0', 'sign_type' => 'MD5', 'mch_id' => $bankmch_id, 'out_trade_no' => $orderid, 'nonce_str' => getNonceStr(32));
	$sign = MakeSign($data, $bankpaykey);
	$data['sign'] = $sign;
	$xml = ToXml($data);
	$resp = ihttp_request('https://pay.swiftpass.cn/pay/gateway', $xml);
	$result = FromXml($resp['content']);
	return $result;
}
function ymf_micropay($code, $fee, $orderid, $cfg)
{
	global $_W;
	$trade = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_order') . ' WHERE id=:a ', array(':a' => $orderid));
	$shop = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_group') . ' WHERE id=:a ', array(':a' => $trade['groupid']));
	$customerid = $shop['customerid'] ? $shop['customerid'] : $cfg['customerid'];
	$secret = $shop['customerkey'] ? $shop['customerkey'] : $cfg['customerkey'];
	load()->func('communication');
	$data = array('userid' => '', 'customerid' => $customerid, 'ordermoney' => $fee, 'truemoney' => $fee, 'longcode' => $code, 'datafrom' => 'j_hmoney', 'syt_id' => $shop['id']);
	ksort($data);
	$o = '';
	foreach ($data as $k => $v) {
		$o .= $k . '=' . $v . '&';
	}
	$post_data = substr($o, 0, 0 - 1);
	$post_data_temp = $secret . $post_data;
	$sign = strtoupper(md5($post_data_temp));
	$post_data .= '&sign=' . $sign;
	$post_str = str_replace('&', '/', $post_data);
	$post_str = str_replace('=', '/', $post_str);
	$postUrl = $cfg['customerurl'] . 'index.php?s=/Home/linenew/m_shoukuan/' . $post_str;
	$resp = ihttp_request($postUrl);
	$result = @json_decode($resp['content'], true);
	if (!isset($result['result'])) {
		return array('success' => false, 'msg' => '接口异常0x001,备注：' . implode(',', $data) . '||' . $postUrl);
	}
	if ($result['result'] == 1 && $result['orderno'] != NULL) {
		return ymf_checkpay($result['orderno'], $shop['id'], $cfg);
	}
	return array('success' => false, 'msg' => '支付失败');
}
function ymf_checkpay($orderno, $shopid, $cfg)
{
	global $_W;
	$shop = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_group') . ' WHERE id=:a ', array(':a' => $shopid));
	$customerid = $shop['customerid'] ? $shop['customerid'] : $cfg['customerid'];
	$secret = $shop['customerkey'] ? $shop['customerkey'] : $cfg['customerkey'];
	load()->func('communication');
	$data = array('orderno' => $orderno, 'uid' => $customerid);
	ksort($data);
	$o = '';
	foreach ($data as $k => $v) {
		$o .= $k . '=' . $v . '&';
	}
	$post_data = substr($o, 0, 0 - 1);
	$post_data_temp = $secret . $post_data;
	$sign = strtoupper(md5($post_data_temp));
	$post_data .= '&sign=' . $sign;
	$post_str = str_replace('&', '/', $post_data);
	$post_str = str_replace('=', '/', $post_str);
	$postUrl = $cfg['customerurl'] . 'index.php?s=/Home/line/m_querypay/' . $post_str;
	$resp = ihttp_request($postUrl);
	$result = @json_decode($resp['content'], true);
	if (!isset($result['status'])) {
		return array('success' => false, 'msg' => '接口异常0x002,备注：' . implode(',', $result));
	}
	if ($result['money'] != NULL && $result['transId'] != NULL) {
		$openid = '';
		if ($result['uuid']) {
			$temp = @implode('|||', $result['uuid']);
			$openid = $temp[1];
		}
		return array('success' => true, 'orderno' => $result['orderno'], 'money' => $result['money'], 'transid' => $result['transid'], 'dztype' => $result['dztype'], 'uuid' => $openid, 'paytime' => $result['paytime']);
	}
	return array('success' => false, 'msg' => '支付失败,备注：' . implode(',', $result));
}
function ymf_refund($orderno, $shopid, $cfg)
{
	global $_W;
	$result = ymf_checkpay($orderno, $shopid, $cfg);
	if ($result['success'] != true) {
		return array('success' => false, 'msg' => '接口异常0x003，备注' . implode(',', $result));
	}
	if ($result['dztype'] == 1) {
		return array('success' => false, 'msg' => '即时到账订单不允许退款');
	}
	load()->func('communication');
	$shop = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_group') . ' WHERE id=:a ', array(':a' => $shopid));
	$customerid = $shop['customerid'] ? $shop['customerid'] : $cfg['customerid'];
	$secret = $shop['customerkey'] ? $shop['customerkey'] : $cfg['customerkey'];
	$data = array('orderno' => $orderno, 'uid' => $customerid);
	ksort($data);
	$o = '';
	foreach ($data as $k => $v) {
		$o .= $k . '=' . $v . '&';
	}
	$post_data = substr($o, 0, 0 - 1);
	$post_data_temp = $secret . $post_data;
	$sign = strtoupper(md5($post_data_temp));
	$post_data .= '&sign=' . $sign;
	$post_str = str_replace('&', '/', $post_data);
	$post_str = str_replace('=', '/', $post_str);
	$postUrl = $cfg['customerurl'] . 'index.php?s=/Home/line/m_backpay/' . $post_str;
	$resp = ihttp_request($postUrl);
	$result = @json_decode($resp['content'], true);
	if (!isset($result['result'])) {
		return array('success' => false, 'msg' => '接口异常0x004，备注' . implode(',', $result));
	}
	if (strval($result['result']) == '0000' && isset($result['amount'])) {
		return array('success' => true, 'orderno' => $result['orderno'], 'transId' => $result['transId']);
	}
	return array('success' => false, 'msg' => '退款失败' . $result['desc']);
}
function getNonceStr($length = 32)
{
	$chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
	$str = '';
	$i = 0;
	while ($i < $length) {
		$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
		$i = $i + 1;
	}
	return $str;
}
function ToUrlParams($parama = array())
{
	$buff = '';
	foreach ($parama as $k => $v) {
		if ($k != 'sign' && $v != '' && !is_array($v)) {
			$buff .= $k . '=' . $v . '&';
		}
	}
	$buff = trim($buff, '&');
	return $buff;
}
function postXmlCurl($xml, $url, $second = 30)
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_TIMEOUT, $second);
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
	$data = curl_exec($ch);
	if ($data) {
		curl_close($ch);
		return $data;
	}
	$error = curl_errno($ch);
	curl_close($ch);
	return 'curl出错，错误码:' . $error;
}
function postXmlAndPemCurl($xml, $url, $pemary)
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_TIMEOUT, $second);
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');
	curl_setopt($ch, CURLOPT_SSLCERT, $pemary['cert']);
	curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');
	curl_setopt($ch, CURLOPT_SSLKEY, $pemary['key']);
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
	$data = curl_exec($ch);
	if ($data) {
		curl_close($ch);
		return $data;
	}
	$error = curl_errno($ch);
	curl_close($ch);
	return 'curl出错，错误码:' . $error;
}
function ToXml($parama = array())
{
	$xml = '<xml>';
	foreach ($parama as $key => $val) {
		if (is_numeric($val)) {
			$xml .= '<' . $key . '>' . $val . '</' . $key . '>';
		} else {
			$xml .= '<' . $key . '><![CDATA[' . $val . ']]></' . $key . '>';
		}
	}
	$xml .= '</xml>';
	return $xml;
}
function FromXml($xml)
{
	if (!$xml) {
		return 'xml数据异常！';
	}
	libxml_disable_entity_loader(true);
	$result = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
	return $result;
}
function MakeSign($parama = array(), $key)
{
	ksort($parama);
	$string = ToUrlParams($parama);
	$string = $string . '&key=' . $key;
	$string = md5($string);
	$result = strtoupper($string);
	return $result;
}
function GetBankType($type = 'CFT')
{
	if (!$type) {
		return false;
	}
	$data = array('CFT' => '零钱包', 'ICBC_DEBIT' => '工商银行(借记卡)', 'ICBC_CREDIT' => '工商银行(信用卡)', 'ABC_DEBIT' => '农业银行(借记卡)', 'ABC_CREDIT' => '农业银行(信用卡)', 'PSBC_DEBIT' => '邮政储蓄银行(借记卡)', 'PSBC_CREDIT' => '邮政储蓄银行(信用卡)', 'CCB_DEBIT' => '建设银行(借记卡)', 'CCB_CREDIT' => '建设银行(信用卡)', 'CMB_DEBIT' => '招商银行(借记卡)', 'CMB_CREDIT' => '招商银行(信用卡)', 'BOC_DEBIT' => '中国银行(借记卡)', 'BOC_CREDIT' => '中国银行(信用卡)', 'COMM_DEBIT' => '交通银行(借记卡)', 'SPDB_DEBIT' => '浦发银行(借记卡)', 'SPDB_CREDIT' => '浦发银行(信用卡)', 'GDB_DEBIT' => '广发银行(借记卡)', 'GDB_CREDIT' => '广发银行(信用卡)', 'CMBC_DEBIT' => '民生银行(借记卡)', 'CMBC_CREDIT' => '民生银行(信用卡)', 'PAB_DEBIT' => '平安银行(借记卡)', 'PAB_CREDIT' => '平安银行(信用卡)', 'CEB_DEBIT' => '光大银行(借记卡)', 'CEB_CREDIT' => '光大银行(信用卡)', 'CIB_DEBIT' => '兴业银行(借记卡)', 'CIB_CREDIT' => '兴业银行(信用卡)', 'CITIC_DEBIT' => '中信银行(借记卡)', 'CITIC_CREDIT' => '中信银行(信用卡)', 'BOSH_DEBIT' => '上海银行(借记卡)', 'BOSH_CREDIT' => '上海银行(信用卡)', 'CRB_DEBIT' => '华润银行(借记卡)', 'HZB_DEBIT' => '杭州银行(借记卡)', 'HZB_CREDIT' => '杭州银行(信用卡)', 'BSB_DEBIT' => '包商银行(借记卡)', 'BSB_CREDIT' => '包商银行(信用卡)', 'CQB_DEBIT' => '重庆银行(借记卡)', 'SDEB_DEBIT' => '顺德农商行(借记卡)', 'SZRCB_DEBIT' => '深圳农商银行(借记卡)', 'HRBB_DEBIT' => '哈尔滨银行(借记卡)', 'BOCD_DEBIT' => '成都银行(借记卡)', 'GDNYB_DEBIT' => '南粤银行(借记卡)', 'GDNYB_CREDIT' => '南粤银行(信用卡)', 'GZCB_DEBIT' => '广州银行(借记卡)', 'GZCB_CREDIT' => '广州银行(信用卡)', 'JSB_DEBIT' => '江苏银行(借记卡)', 'JSB_CREDIT' => '江苏银行(信用卡)', 'NBCB_DEBIT' => '宁波银行(借记卡)', 'NBCB_CREDIT' => '宁波银行(信用卡)', 'NJCB_DEBIT' => '南京银行(借记卡)', 'JZB_DEBIT' => '晋中银行(借记卡)', 'KRCB_DEBIT' => '昆山农商(借记卡)', 'LJB_DEBIT' => '龙江银行(借记卡)', 'LNNX_DEBIT' => '辽宁农信(借记卡)', 'LZB_DEBIT' => '兰州银行(借记卡)', 'WRCB_DEBIT' => '无锡农商(借记卡)', 'ZYB_DEBIT' => '中原银行(借记卡)', 'ZJRCUB_DEBIT' => '浙江农信(借记卡)', 'WZB_DEBIT' => '温州银行(借记卡)', 'XAB_DEBIT' => '西安银行(借记卡)', 'JXNXB_DEBIT' => '江西农信(借记卡)', 'NCB_DEBIT' => '宁波通商银行(借记卡)', 'NYCCB_DEBIT' => '南阳村镇银行(借记卡)', 'NMGNX_DEBIT' => '内蒙古农信(借记卡)', 'SXXH_DEBIT' => '陕西信合(借记卡)', 'SRCB_CREDIT' => '上海农商银行(信用卡)', 'SJB_DEBIT' => '盛京银行(借记卡)', 'SDRCU_DEBIT' => '山东农信(借记卡)', 'SRCB_DEBIT' => '上海农商银行(借记卡)', 'SCNX_DEBIT' => '四川农信(借记卡)', 'QLB_DEBIT' => '齐鲁银行(借记卡)', 'QDCCB_DEBIT' => '青岛银行(借记卡)', 'PZHCCB_DEBIT' => '攀枝花银行(借记卡)', 'ZJTLCB_DEBIT' => '浙江泰隆银行(借记卡)', 'TJBHB_DEBIT' => '天津滨海农商行(借记卡)', 'WEB_DEBIT' => '微众银行(借记卡)', 'YNRCCB_DEBIT' => '云南农信(借记卡)', 'WFB_DEBIT' => '潍坊银行(借记卡)', 'WHRC_DEBIT' => '武汉农商行(借记卡)', 'ORDOSB_DEBIT' => '鄂尔多斯银行(借记卡)', 'XJRCCB_DEBIT' => '新疆农信银行(借记卡)', 'ORDOSB_CREDIT' => '鄂尔多斯银行(信用卡)', 'CSRCB_DEBIT' => '常熟农商银行(借记卡)', 'JSNX_DEBIT' => '江苏农商行(借记卡)', 'GRCB_CREDIT' => '广州农商银行(信用卡)', 'GLB_DEBIT' => '桂林银行(借记卡)', 'GDRCU_DEBIT' => '广东农信银行(借记卡)', 'GDHX_DEBIT' => '广东华兴银行(借记卡)', 'FJNX_DEBIT' => '福建农信银行(借记卡)', 'DYCCB_DEBIT' => '德阳银行(借记卡)', 'DRCB_DEBIT' => '东莞农商行(借记卡)', 'CZCB_DEBIT' => '稠州银行(借记卡)', 'CZB_DEBIT' => '浙商银行(借记卡)', 'CZB_CREDIT' => '浙商银行(信用卡)', 'GRCB_DEBIT' => '广州农商银行(借记卡)', 'CSCB_DEBIT' => '长沙银行(借记卡)', 'CQRCB_DEBIT' => '重庆农商银行(借记卡)', 'CBHB_DEBIT' => '渤海银行(借记卡)', 'BOIMCB_DEBIT' => '内蒙古银行(借记卡)', 'BOD_DEBIT' => '东莞银行(借记卡)', 'BOD_CREDIT' => '东莞银行(信用卡)', 'BOB_DEBIT' => '北京银行(借记卡)', 'BNC_DEBIT' => '江西银行(借记卡)', 'BJRCB_DEBIT' => '北京农商行(借记卡)', 'AE_CREDIT' => 'AE(信用卡)', 'GYCB_CREDIT' => '贵阳银行(信用卡)', 'JSHB_DEBIT' => '晋商银行(借记卡)', 'JRCB_DEBIT' => '江阴农商行(借记卡)', 'JNRCB_DEBIT' => '江南农商(借记卡)', 'JLNX_DEBIT' => '吉林农信(借记卡)', 'JLB_DEBIT' => '吉林银行(借记卡)', 'JJCCB_DEBIT' => '九江银行(借记卡)', 'HXB_DEBIT' => '华夏银行(借记卡)', 'HXB_CREDIT' => '华夏银行(信用卡)', 'HUNNX_DEBIT' => '湖南农信(借记卡)', 'HSB_DEBIT' => '徽商银行(借记卡)', 'HSBC_DEBIT' => '恒生银行(借记卡)', 'HRXJB_DEBIT' => '华融湘江银行(借记卡)', 'HNNX_DEBIT' => '河南农信(借记卡)', 'HKBEA_DEBIT' => '东亚银行(借记卡)', 'HEBNX_DEBIT' => '河北农信(借记卡)', 'HBNX_DEBIT' => '湖北农信(借记卡)', 'HBNX_CREDIT' => '湖北农信(信用卡)', 'GYCB_DEBIT' => '贵阳银行(借记卡)', 'GSNX_DEBIT' => '甘肃农信(借记卡)', 'JCB_CREDIT' => 'JCB(信用卡)', 'MASTERCARD_CREDIT' => 'MASTERCARD(信用卡)', 'VISA_CREDIT' => 'VISA(信用卡)');
	return $data[$type];
}
function isMobile()
{
	if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
		return true;
	}
	if (isset($_SERVER['HTTP_VIA'])) {
		return stristr($_SERVER['HTTP_VIA'], 'wap') ? true : false;
	}
	if (isset($_SERVER['HTTP_USER_AGENT'])) {
		$clientkeywords = array('nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile');
		if (preg_match('/(' . implode('|', $clientkeywords) . ')/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
			return true;
		}
	}
	if (isset($_SERVER['HTTP_ACCEPT'])) {
		if (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))) {
			return true;
		}
	}
	return false;
}
function encrypt($string, $operation, $key = '')
{
	$key = md5($key);
	$key_length = strlen($key);
	$string = $operation == 'D' ? base64_decode($string) : substr(md5($string . $key), 0, 8) . $string;
	$string_length = strlen($string);
	$rndkey = $box = array();
	$result = '';
	$i = 0;
	while ($i <= 255) {
		$rndkey[$i] = ord($key[$i % $key_length]);
		$box[$i] = $i;
		$i = $i + 1;
	}
	$j = $i = 0;
	while ($i < 256) {
		$j = ($j + $box[$i] + $rndkey[$i]) % 256;
		$tmp = $box[$i];
		$box[$i] = $box[$j];
		$box[$j] = $tmp;
		$i = $i + 1;
	}
	$a = $j = $i = 0;
	while ($i < $string_length) {
		$a = ($a + 1) % 256;
		$j = ($j + $box[$a]) % 256;
		$tmp = $box[$a];
		$box[$a] = $box[$j];
		$box[$j] = $tmp;
		$result .= chr(ord($string[$i]) ^ $box[($box[$a] + $box[$j]) % 256]);
		$i = $i + 1;
	}
	if ($operation == 'D') {
		if (substr($result, 0, 8) == substr(md5(substr($result, 8) . $key), 0, 8)) {
			return substr($result, 8);
		}
		return '';
	}
	return str_replace('=', '', base64_encode($result));
}
function getAccessToken($id)
{
	if (!$id) {
		return false;
	}
	$item = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_group') . ' WHERE id = :a', array(':a' => $id));
	if (!$item['token'] || !$item['expire_time'] || TIMESTAMP > $item['expire_time']) {
		if (!$item['appid'] || !$item['appsecret']) {
			return false;
		}
		load()->func('communication');
		$urls = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $item['appid'] . '&secret=' . $item['appsecret'] . '';
		$content = ihttp_get($urls);
		if (is_error($content)) {
			return false;
		}
		$result = @json_decode($content['content'], true);
		if (empty($result) || !is_array($result) || empty($result['access_token']) || empty($result['expires_in'])) {
			$errorinfo = substr($content['meta'], strpos($content['meta'], '{'));
			$errorinfo = @json_decode($errorinfo, true);
			if (is_error($content)) {
				return false;
			}
		}
		$data['token'] = $result['access_token'];
		$data['expire_time'] = TIMESTAMP + $result['expires_in'];
		pdo_update('j_hmoney_group', $data, array('id' => $id));
		return $data['token'];
	}
	if (TIMESTAMP < $item['expire_time']) {
		return $token;
	}
	return null;
}
function trueUrl2Shorturl($longurl)
{
	global $_W;
	load()->func('communication');
	$acid = pdo_fetchcolumn('SELECT acid FROM ' . tablename('account') . ' WHERE uniacid=:uniacid ', array(':uniacid' => $_W['uniacid']));
	$acc = WeAccount::create($acid);
	$tokens = $acc->fetch_token();
	$url = 'https://api.weixin.qq.com/cgi-bin/shorturl?access_token=' . $tokens;
	$data = array('action' => 'long2short', 'long_url' => $longurl);
	$content = ihttp_post($url, json_encode($data));
	if (is_error($content)) {
		return false;
	}
	$result = @json_decode($content['content'], true);
	if (empty($result) || !is_array($result) || $result['errcode'] != 0) {
		return false;
	}
	return $result['short_url'];
}
function _openid2card($openid)
{
	global $_W;
	if (!$openid) {
		return false;
	}
	$card = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_memebercard') . ' WHERE openid=:openid ', array(':openid' => $openid));
	if (!$card) {
		return false;
	}
	return $card;
}
function getUserMemberCard($openid)
{
	global $_W;
	if (!$openid) {
		return false;
	}
	load()->func('communication');
	$acid = pdo_fetchcolumn('SELECT acid FROM ' . tablename('account') . ' WHERE uniacid=:uniacid ', array(':uniacid' => $_W['uniacid']));
	$acc = WeAccount::create($acid);
	$tokens = $acc->fetch_token();
	$pageparama = json_encode(array('openid' => $openid));
	$resp = ihttp_request('https://api.weixin.qq.com/card/user/getcardlist?access_token=' . $tokens, $pageparama, $xml);
	if (is_error($resp)) {
		$procResult = $resp;
	}
	$result = @json_decode($resp['content'], true);
	return $result;
}
function countTxtLen($txt = '', $len = 0, $type = 1)
{
	$result = $txt;
	if ($type == 1) {
		$txtlen = strlen($txt);
		if ($txtlen > $len) {
			$result = substr($txt, 0, $len);
		} else {
			if ($txtlen <= $len) {
				$i = 0;
				while ($i < $len - $txtlen) {
					$result .= ' ';
					$i = $i + 1;
				}
			}
		}
	} else {
		$txtlen = (strlen($txt) + mb_strlen($txt, 'UTF8')) / 2;
		if ($txtlen % 2 != 0) {
			$result .= ' ';
			$txtlen = (strlen($result) + mb_strlen($result, 'UTF8')) / 2;
		}
		if ($txtlen > $len) {
			$result = mb_substr($txt, 0, $len, 'utf-8');
		} else {
			if ($txtlen <= $len) {
				$i = 0;
				while ($i < ($len - $txtlen) / 2) {
					$result .= '　';
					$i = $i + 1;
				}
			}
		}
	}
	return $result;
}
function getFirstCharter($str)
{
	if (empty($str)) {
		return '';
	}
	$fchar = ord($str[0]);
	if ($fchar >= ord('A') && $fchar <= ord('z')) {
		return strtoupper($str[0]);
	}
	$s1 = iconv('UTF-8', 'gb2312', $str);
	$s2 = iconv('gb2312', 'UTF-8', $s1);
	$s = $s2 == $str ? $s1 : $str;
	$asc = ord($s[0]) * 256 + ord($s[1]) - 65536;
	if ($asc >= 0 - 20319 && $asc <= 0 - 20284) {
		return 'A';
	}
	if ($asc >= 0 - 20283 && $asc <= 0 - 19776) {
		return 'B';
	}
	if ($asc >= 0 - 19775 && $asc <= 0 - 19219) {
		return 'C';
	}
	if ($asc >= 0 - 19218 && $asc <= 0 - 18711) {
		return 'D';
	}
	if ($asc >= 0 - 18710 && $asc <= 0 - 18527) {
		return 'E';
	}
	if ($asc >= 0 - 18526 && $asc <= 0 - 18240) {
		return 'F';
	}
	if ($asc >= 0 - 18239 && $asc <= 0 - 17923) {
		return 'G';
	}
	if ($asc >= 0 - 17922 && $asc <= 0 - 17418) {
		return 'H';
	}
	if ($asc >= 0 - 17417 && $asc <= 0 - 16475) {
		return 'J';
	}
	if ($asc >= 0 - 16474 && $asc <= 0 - 16213) {
		return 'K';
	}
	if ($asc >= 0 - 16212 && $asc <= 0 - 15641) {
		return 'L';
	}
	if ($asc >= 0 - 15640 && $asc <= 0 - 15166) {
		return 'M';
	}
	if ($asc >= 0 - 15165 && $asc <= 0 - 14923) {
		return 'N';
	}
	if ($asc >= 0 - 14922 && $asc <= 0 - 14915) {
		return 'O';
	}
	if ($asc >= 0 - 14914 && $asc <= 0 - 14631) {
		return 'P';
	}
	if ($asc >= 0 - 14630 && $asc <= 0 - 14150) {
		return 'Q';
	}
	if ($asc >= 0 - 14149 && $asc <= 0 - 14091) {
		return 'R';
	}
	if ($asc >= 0 - 14090 && $asc <= 0 - 13319) {
		return 'S';
	}
	if ($asc >= 0 - 13318 && $asc <= 0 - 12839) {
		return 'T';
	}
	if ($asc >= 0 - 12838 && $asc <= 0 - 12557) {
		return 'W';
	}
	if ($asc >= 0 - 12556 && $asc <= 0 - 11848) {
		return 'X';
	}
	if ($asc >= 0 - 11847 && $asc <= 0 - 11056) {
		return 'Y';
	}
	if ($asc >= 0 - 11055 && $asc <= 0 - 10247) {
		return 'Z';
	}
	return NULL;
}
function formatPrintStr($str, $num = 0, $rightOrLeft = 0)
{
	$len = mb_strwidth($str, 'UTF8');
	if ($len > $num) {
		return mb_strimwidth($str, 0, $num - 4, '…', 'utf8');
	}
	if ($len == $num) {
		return $str;
	}
	$temp = '';
	$i = 0;
	while ($i < $num - $len) {
		$temp .= ' ';
		$i = $i + 1;
	}
	if ($rightOrLeft) {
		return $temp . $str;
	}
	return $str . $temp;
}